package com.net.traffic;

import android.app.Activity;
import android.net.TrafficStats;
import android.os.Bundle;
import android.util.Log;

public class Android_NetTrafficActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
//  static long  getUidRxBytes(int uid)  //获取某个网络UID的接受字节数
//  static long  getUidTxBytes(int uid) //获取某个网络UID的发送字节数 
    public static void getInfo(){
    	long mrb=TrafficStats.getMobileRxBytes();
    	long mrp=TrafficStats.getMobileRxPackets();
    	long mtb=TrafficStats.getMobileTxBytes();
    	long mtp=TrafficStats.getMobileTxPackets();
    	long trb=TrafficStats.getTotalRxBytes();
    	long trp=TrafficStats.getTotalRxPackets();
    	long ttb=TrafficStats.getTotalTxBytes();
    	long ttp=TrafficStats.getTotalTxPackets();
    	print("mrb",mrb);
    	print("mrp",mrp);
    	print("mtb",mtb);
    	print("mtp",mtp);
    	print("trb",trb);
    	print("trp",trp);
    	print("ttb",ttb);
    	print("ttp",ttp);
    }
    
    public static void print(String str,long l){
    	Log.e(str, String.valueOf(l));
    }
    public static void print(String str,CharSequence l){
    	Log.e(str, l.toString());
    }
    public static void print(String str,String l){
    	if(str==null)
    		str="";
    	if(l==null)
    		l="";
    	Log.e(str, l);
    }
}